<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>广东省传播平台-物料库新增</title>
		<style>
		#organizesTree {
			margin-top: 10px;
			border: 1px solid #617775;
			background: #f0f6e4;
			min-width: 180px;
			max-height: 400px;
			overflow-y: scroll;
			overflow-x: auto;
		}
		</style>
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/tag.css" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/common.css" />
        <script type="text/javascript" src="<%=path%>/js/My97DatePicker/WdatePicker.js">
        </script>
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/tag.css" />
		<link type="text/css" rel="stylesheet" href="<%=path%>/css/zTreeStyle/zTreeStyle.css" />	
		<link type="text/css" href="<%=path%>/js/jquery-ui-1.8.21.custom/css/smoothness/jquery-ui-1.8.21.custom.css" rel="stylesheet" />
		<script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.js"></script>
		<script type="text/javascript" src="<%=path%>/js/jquery.ztree.core-3.1.js"></script>
		<script type="text/javascript" src="<%=path%>/js/jquery.ztree.excheck-3.1.min.js"></script>
		<script type="text/javascript" src="<%=path%>/js/jquery-ui-1.8.21.custom/js/jquery-ui-1.8.21.custom.min.js">
		</script>
		<script type="text/javascript">
		
			function doSubmit(url){
				document.forms[0].action=url;
				//document.forms[0].submit();
				document.getElementById("frmID").action=url;
                document.getElementById("frmID").submit();
			}
			function cancle(url)
		    {
		      if(confirm("您确认取消本次操作？"))
		      {
		         doSubmit(url);
		      }

		    }  
			
            //对新增进行校验
			function addSubFrm() {
			
				var myReg = /^[^@\/\'\\\"#$%&\^\*<>]+$/;
			
				//物料名称
				var tmpContractID = trim(document.getElementById("materialName").value);
				document.getElementById("materialName").value = tmpContractID;
				if (tmpContractID == '') {
					alert('物料名称不能为空！');
					return false;
				}
				if(!myReg.test(tmpContractID)){
				    alert('物料名称不能包含特殊字符！');
				    return false;
				}
				if (getLen(tmpContractID)>100) {
					alert('物料名称的字符个数不允许超过100位（汉字33个）！');
					return false;
				}
				//上线时间
				var tmpContractName = trim(document.getElementById("firstUpTime").value);
				if (tmpContractName == '') {
					alert('最初上线时间不能为空！');
					return false;
				}
				//物料排序
				var tmpContractBName = trim(document.getElementById("orderCol").value);
				var pattern   =   /[^\d]/g;
				if (tmpContractBName == '') {
					alert('物料排序不能为空！');
					return false;
				}
				if(pattern.test(tmpContractBName))
				{
				    alert('物料排序请输入1~99之间的整数！');
					return false;
				}
				if(tmpContractBName<1||tmpContractBName>99)
				{
				    alert('物料排序请输入1~99之间的整数！');
				    return false;
				}
				var tmpContractA = trim(document.getElementById("accessory").value);
				if(getLen(tmpContractA)>256){
					alert('物料描述的长度不允许超过256位(汉字85个)！');
					return false;
				}
				var tempMaterialName= document.getElementById("materialName").value;
				var tempMaterialType= document.getElementById("materialType").value;
				var tempMaterialOwnCity= document.getElementById("ownCity").value;
				var tempMaterialServiceType= document.getElementById("serviceType").value;
				var tempMaterialFirstuptime1= document.getElementById("firstUpTime").value;
				var tempMaterialFirstuptime2= document.getElementById("firstUpTime").value;
				tempMaterialFirstuptime1 = tempMaterialFirstuptime1.substr(2,2);
				tempMaterialFirstuptime2 = tempMaterialFirstuptime2.substr(5,2);
				var tempMaterialFirstuptime = tempMaterialFirstuptime1+tempMaterialFirstuptime2;
				var tempMaterialOrderCol= document.getElementById("orderCol").value;
				if(tempMaterialOrderCol<10){
	                tempMaterialOrderCol = "0"+tempMaterialOrderCol;			
				}
				var tempMaterial =tempMaterialOwnCity+"-"+tempMaterialServiceType+"-"+tempMaterialType+"-"+tempMaterialFirstuptime+"-"+tempMaterialOrderCol+"-"+tempMaterialName;
				
				var url = encodeURI(encodeURI('isExistMaterialID.action?tempMaterial=' + tempMaterial));
					$.ajax( {
						url : url,
						type : "POST",
						cache : false,
						success : function(message) {
							if (message == "success") {
								alert("物料信息已存在！");
								$(this).focus();
							} 
							else{
								doSubmit('saveMaterialAction.action');
							}
						}
					});
				return true;
				
			}
			function trim(str) {
				str = str.replace(/^\s*/, "");
				str = str.replace(/\s*$/, "");
				str = str.replace(/^[" "|"　"]*/, "");
				str = str.replace(/[" "|"　"]*$/, "");
				return str;
			}
			function getLen(str){
				var len=0;
				if(null!=str&&str!=""){
					for(var i=0;i<str.length;i++){
						var intCode=str.charCodeAt(i);
						//如果ASCII码等于34(")38(&)39(')47(/)60(<)62(>)92(\)也算三个字符
						if (intCode>=0&&intCode<=100&&intCode!=34&&intCode!=39&&intCode!=47&&intCode!=60&&intCode!=62&&intCode!=92){
							len=len+1;
						}else{
							len=len+3;
						}
					}
				}
				return len;
			}
			

		
			
			
       </script>
	</head>

	<body>
		<!-- 顶栏start -->
		<jsp:include page="../common/top.jsp"></jsp:include>
		<!-- 顶栏end -->

		<!-- 顶部start -->
		<div id="main">
			<div class="body">
				<!-- 导航菜单 -->
				<jsp:include page="../common/nav.jsp"></jsp:include>
				
				<!-- 主体 -->
				<div class="main_body">
				<form  id="frmID" method="post" enctype="multipart/form-data">
					<div id="add_div">
						<table class="table_add" style="width: 100%;">

							<tr>
								<th style="width: 150px;">
									物料名称：
								</th>
								<td style="width: 225px;">
									<input  name="material.materialName" id="materialName" value="${materialName}" type="text" 
									class="text" style="width: 225px;" />
									<font color="red" >*</font>
									
								</td>
								
								
								<th style="width: 189px;">
									物料类型：
								</th>
								<td style="width: 225px;">
								<s:select cssStyle="width: 227px;" name="material.materialType" id="materialType" list="dataListWLLX"
										listKey="id" listValue="datavalue" 
										>
								</s:select>
								<font color="red" >*</font>
								</td>
							</tr>


							<tr>
								<th style="width: 150px;">
									归属地市：
								</th>
								<td style="width: 225px;">
									<s:select  cssStyle="width: 227px;" name="material.ownCity" id="ownCity" list="dataListCITY"
										listKey="id" listValue="datavalue" >
									</s:select>
									<font color="red" >*</font>
								</td>
								
								<th style="width: 189px;">
									业务类型：
								</th>
								<td style="width: 225px;">
								<s:select  cssStyle="width: 227px;" name="material.serviceType" id="serviceType" list="dataListWLYWLX"
										listKey="id" listValue="datavalue" >
								</s:select>
								<font color="red" >*</font>
								</td>
							</tr>
							
							
							<tr>
								<th style="width: 150px;">
									最初上线时间：
								</th>
								<td style="width: 225px;">
									<input type="text" class="text Wdate" id="firstUpTime" name="material.firstUpTime" id="firstUpTime"  value="${material.firstUpTime}"
										onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'} )"  readonly="readonly"
										style="width: 225px;" />
										<font color="red" >*</font>
								</td>
								<th style="width: 189px;">
									物料排序：
								</th>
								<td style="width: 225px;">
									<input name="material.orderCol" value="${orderCol}" id="orderCol" type="text" class="text" style="width: 225px;"  />
									<font color="red" >*</font>
								</td>
							</tr>
							
							<tr>
							    <th style="width: 150px;">
									物料级别：
								</th>
								<td style="width: 225px;">
								<s:select  cssStyle="width: 227px;" name="material.materialLevel" id="materialLevel" list="dataListWLJB"
										listKey="id" listValue="datavalue" >
								</s:select>
								<font color="red" >*</font>
								</td>
								
								<th style="width: 189px;">
									部门科室：
								</th>
								<td style="width: 225px;">
								    <input type="hidden" id="orgID" name="material.ownDepartment"/>
								    <input name="text2" type="text" class="text" id="showOrganize"
										style="width: 225px;" onkeydown="if(event.keyCode==8)return false;"
										onclick="showMenu('showOrganize', 'organizeContent');" value="" readonly="readonly"/>
								</td>
								
							</tr>

							<tr>
								<th style="width: 150px;">
									物料描述：
								</th>
								<td colspan="3">
									<textarea name="material.accessory" id="accessory"
										style="width: 647px; font-family: '微软雅黑'; font-size: 12px; font-weight: bold; color: #666666;"></textarea>
								</td>
							</tr>




							<tr>
								<th style="width: 150px;">
									物料文件：
								</th>
								<td colspan="3">
									<input type="file" name="inputfile" 
										style="width: 225px;height:22px; border: solid 1px #999999;" />
								</td>
							</tr>


						</table>
					</div>
					<div style="margin: 8px 0 0 150px;">
						<input type="button" class="btn-title"  value="保存"
						onclick="addSubFrm();"/>
						&nbsp;&nbsp;
						<input type="button" class="btn-title" value="取消"
							onclick="cancle('materiallist.action');" />
					</div>
				</form>
				</div>
			</div>
		</div>
		<div id="organizeContent" class="menuContent"
			style="display: none; position: absolute;">
			<ul id="organizesTree" class="ztree" style="margin-top: 0;"></ul>
		</div>
   
		<!-- 顶部end -->
		<!-- 底部start -->
		<jsp:include page="/jsp/common/bottom.jsp"></jsp:include>
		<!-- 底部end -->
		<div id="tempDiv"></div>
		<script type="text/javascript">
			
			//获取后台数据显示组织架构
			var organizes =${flag};
			
			//组织架构初始化
			var organizeSetting = {
				view : {
					dblClickExpand : false
				},
				data : {
					simpleData : {
						enable : true
					}
				},
				callback : {
					beforeClick : beforeClick,
					onClick : organizeOnClick
				}
			};
				//页面加载
			$(function() {
				//设置组织架构弹出框
				$.fn.zTree.init($("#organizesTree"), organizeSetting, organizes);
				
			});
		
			//点击事件
			function beforeClick(treeId, treeNode) {
				var check = (treeNode && !treeNode.isParent);
				if (!check)
					alert("请选择下级节点！");
				return check;
			}
		
			//组织架构点击事件
			function organizeOnClick(e, treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("organizesTree"), nodes = zTree.getSelectedNodes(), v = "";
				nodes.sort(function compare(a, b) {
					return a.id - b.id;
				});
				for ( var i = 0, l = nodes.length; i < l; i++) {
					v += nodes[i].name + ",";
				}
				if (v.length > 0)
					v = v.substring(0, v.length - 1);
				var orgNameObj = $("#showOrganize");
				orgNameObj.attr("value", v);
				//设置隐藏域中组织编号  
				$('#orgID').val(treeNode.id);
				hideMenu('organizeContent');
			}
		
			//隐藏组织架构
			function hideMenu(divId) {
				$("#" + divId).fadeOut("fast");
				$("body").unbind("mousedown", {
					tempDiv : divId
				}, onBodyDown);
			}
		
			//组织架构弹出窗
			function showMenu(objId, divId) {
				var cityObj = $("#" + objId);
				var cityOffset = $("#" + objId).position();
				$("#" + divId).css( {
					left : cityOffset.left + "px",
					top : cityOffset.top + cityObj.outerHeight() + "px"
				}).slideDown("fast");
				$("body").bind("mousedown", {
					tempDiv : divId
				}, onBodyDown);
			}
				//鼠标点击别的地方隐藏弹出属性菜单
			function onBodyDown(event) {
				var divId = event.data.tempDiv;
				if (!(event.target.id == "showOrganize" || $(event.target).parents(
						"#" + divId).length > 0)) {
					hideMenu(divId);
				}
			}
				//组织架构 showOrganize
		//	if(!paramIsNull('showOrganize'))
		//	{	
		//		alert('请选择用户所属组织架构！');
		//		return false;
		//	}
			
				//参数非空验证
			function paramIsNull(paramId){
				var temp = $('#'+paramId).val();
				if(null == temp || temp=='')
				{
					return false;
				}
				else{
					//文本框去左右空格重新赋值
					$('#'+paramId).val($.trim(temp));
					return true;
				}
			} 
			
			
			</script>
		
	</body>
</html>
